/**************************************************************
 * common.h - 
 * Copyright (c) 2009  Qin Xiaoxue  <crs.chin@gmail.com>
 *
 * This file is  free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
**************************************************************/


#ifndef __COMMON_H
#define __COMMON_H

#include <stdio.h>
#include <sys/types.h>
#include <glib.h>
#include <config.h>

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#ifndef PACKAGE_NAME
#define PROG_NAME "lyricplayer"
#else
#define PROG_NAME PACKAGE_NAME
#endif

#ifndef VERSION
#define PROG_VERSION "0.0.1"
#else
#define PROG_VERSION VERSION
#endif

#ifndef PROG_COPYRIGHT
#define PROG_COPYRIGHT "Copyright (C) 2009 Qin Xiaoxue"
#endif

#ifndef PROG_COMMENTS
#define PROG_COMMENTS								\
  "Multiform Lyric Frontends\n"						\
  PROG_NAME " comes with ABSOLUTELY NO WARRANTY;"	\
  " This is free software, and you are welcome"		\
  "to redistribute it under certain conditions"
#endif

#ifndef PROG_LICENSE
#define PROG_LICENSE "GPLv2"
#endif

#ifndef PROG_WEBSITE
#define PROG_WEBSITE "http://code.google.com/p/lyricplayer"
#endif

#ifndef PROG_CONF
#define PROG_CONF PROG_NAME ".conf"
#endif

#ifndef LIB_PREFIX
#error  "** Package config error, LIB_PREFIX undefined, abort."
#endif


#ifndef CONFIG_CLIENT_BASEDIR
#define CONFIG_CLIENT_BASEDIR LIB_PREFIX PROG_NAME "/PlayerControl/"
#endif
#define CLIENT_BASEDIR  CONFIG_CLIENT_BASEDIR

#ifndef CONFIG_UI_BASEDIR
#define CONFIG_UI_BASEDIR LIB_PREFIX PROG_NAME "/UI/"
#endif
#define UI_BASEDIR CONFIG_UI_BASEDIR


#ifndef CONFIG_FETCHLYRIC_BASEDIR
#define CONFIG_FETCHLYRIC_BASEDIR LIB_PREFIX PROG_NAME "/FetchLyric/"
#endif
#define FETCHLYRIC_BASEDIR CONFIG_FETCHLYRIC_BASEDIR


/* default UI modules configurations */
#define  UI_CLI_DEFAULT_CONFIG							\
  "[General]\nclient_backend=XMMS2\nlyric_plugin=all\n"	\
  "no_lyric_wait=YES\nexit_on_quit=NO\n"

#define  UI_GOSD_DEFAULT_CONFIG								\
  "[General]\nfont=Penguin Attack 28\ncolor_red=1\n"		\
  "color_green=0\ncolor_blue=0\n"							\
  "color_alpha=0.8999999999999999\nposition_x=-50\n"		\
  "position_y=-50\nautoselect=true\nselect_timeout=10\n"	\
  "with_shadow=true\n"

/* default main  configurations */
#define  MAIN_DEFAULT_CONFIG				""


#ifndef NDEBUG
#define DBGMSG(fmt,...)							\
  do  {											\
	fprintf(stderr, "DBGMSG:" fmt,##__VA_ARGS__);	\
  }while(0)
#else
#define DBGMSG(fmt,...)  do{}while(0)
#endif


#define get_data_struct(type)					\
  type *get_##type()							\
  {												\
	type *x;									\
	x=(type *)malloc(sizeof(type));				\
	if(!x)  {									\
	  warn("**run out of memory!aborting...");	\
	  exit (FALSE);								\
	}											\
	memset(x,0,sizeof(type));					\
	return x;									\
  }


extern gboolean quiet;
extern gboolean verbose;

void print_verb(const gchar *fmt, ...);
void print_info(const gchar *fmt, ...);
void print_err(const gchar *fmt, ...);
void print_bug(const gchar *fmt, ...);

void *checked_malloc(size_t size);
void *checked_realloc(void *p, size_t size);

gboolean  file_cat(FILE *from, FILE *to);
gboolean  file_copy(FILE *from, FILE *to);

size_t secure_fread(void *buf, size_t size, size_t nmem, FILE *fstream);
size_t secure_fwrite(void *buf, size_t size, size_t nmem, FILE *fstream);

int isalldigit(const char *str);
char *unescape(const char *str);
char *translate(char *str, const char *from, const char *to);
char *impact(char *str, char *delim, int hunger);
char *strip(char *str, int onlyends);

char *guess_filename(const char *str, char **artist);

#define GREETING								\
""


#endif  /* __COMMON_H */


